using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Linq;

namespace Net35.Xrm.Sdk
{
	[DataContract(Name = "EntityCollection", Namespace = "http://schemas.microsoft.com/xrm/2011/Contracts")]
	public sealed class EntityCollection : IExtensibleDataObject
	{
		private string _entityName;
		private DataCollection<Entity> _entities;
		private bool _moreRecords;
		private string _pagingCookie;
		private string _minActiveRowVersion;
		private int _totalRecordCount;
		private bool _totalRecordCountLimitExceeded;
		private bool _isReadOnly;
		private ExtensionDataObject _extensionDataObject;
		[DataMember]
		public DataCollection<Entity> Entities
		{
			get
			{
				if (this._entities == null)
				{
					this._entities = new DataCollection<Entity>();
				}
				return this._entities;
			}
			private set
			{
				this._entities = value;
			}
		}
		[DataMember]
		public bool MoreRecords
		{
			get
			{
				return this._moreRecords;
			}
			set
			{
				this.CheckIsReadOnly();
				this._moreRecords = value;
			}
		}
		[DataMember]
		public string PagingCookie
		{
			get
			{
				return this._pagingCookie;
			}
			set
			{
				this.CheckIsReadOnly();
				this._pagingCookie = value;
			}
		}
		[DataMember]
		public string MinActiveRowVersion
		{
			get
			{
				return this._minActiveRowVersion;
			}
			set
			{
				this.CheckIsReadOnly();
				this._minActiveRowVersion = value;
			}
		}
		[DataMember]
		public int TotalRecordCount
		{
			get
			{
				return this._totalRecordCount;
			}
			set
			{
				this.CheckIsReadOnly();
				this._totalRecordCount = value;
			}
		}
		[DataMember]
		public bool TotalRecordCountLimitExceeded
		{
			get
			{
				return this._totalRecordCountLimitExceeded;
			}
			set
			{
				this.CheckIsReadOnly();
				this._totalRecordCountLimitExceeded = value;
			}
		}
		public Entity this[int index]
		{
			get
			{
				return this.Entities[index];
			}
			set
			{
				this.CheckIsReadOnly();
				this.Entities[index] = value;
			}
		}
		[DataMember]
		public string EntityName
		{
			get
			{
				return this._entityName;
			}
			set
			{
				this.CheckIsReadOnly();
				this._entityName = value;
			}
		}
		internal bool IsReadOnly
		{
			get
			{
				return this._isReadOnly;
			}
			set
			{
				this._isReadOnly = value;
			}
		}
		public ExtensionDataObject ExtensionData
		{
			get
			{
				return this._extensionDataObject;
			}
			set
			{
				this._extensionDataObject = value;
			}
		}
		public EntityCollection()
		{
		}
		public EntityCollection(List<Entity> list)
		{
			this._entities = new DataCollection<Entity>(list);
		}
		public EntityCollection(IList<Entity> list)
		{
			this._entities = new DataCollection<Entity>(list);
		}
		private void CheckIsReadOnly()
		{
			if (this.IsReadOnly)
			{
				throw new InvalidOperationException("The collection is read-only.");
			}
		}
	}
}
